home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SIHshTbl.h
-
- Contains: Interface to hash table code and SIHashTable class.
-
- Owned by: Nick Pilch
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
-
- */
-
- #ifndef _SIHSHTBL_
- #define _SIHSHTBL_
-
- #ifndef _ODTYPES_
- #include "ODTypes.h"
- #endif
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
- //==============================================================================
- // Theory of Operation
- //==============================================================================
-
- /*
- C Interface to some of the routines in HashTabl.A and class wrapper.
-
- The class simply provides an object-oriented wrapper to the AE hash table
- functions found in HashTable.A. It removes access to the MemHooks parameter. (MemHooks is set to NULL and SysHeap is set to false.)
- It hides the Table parameter since that is a member variable of the class.
- */
-
- //==============================================================================
- // Scalar Types
- //==============================================================================
-
- typedef void* ODEntryPtr;
- typedef void* ODKeyPtr;
- typedef Handle HashTable;
-
-
- //==============================================================================
- // Error Codes
- //==============================================================================
-
- const ODSShort kAEErrAlreadyExists = -1722;
- const ODSShort kAEErrNotFound = -1723;
- const ODSShort kAEErrEndOfTable = -1724;
-
-
- //==============================================================================
- // Classes defined in this interface
- //==============================================================================
-
- class SIHashTable;
- class SIHashTableIterator;
-
- //==============================================================================
- // SIHashTable
- //==============================================================================
-
- class SIHashTable
- {
- friend class SIHashTableIterator;
-
- public:
-
- SIHashTable();
- ODVMethod void Initialize(ODULong numEntries, ODUShort keySize,
- ODUShort valueSize, ODBoolean inSysHeap);
- // kODErrOutOfMemory is thrown if the table cannot be created.
-
- virtual ~SIHashTable();
-
- ODVMethod void ReplaceEntry(ODKeyPtr key, ODEntryPtr value);
- // Replace and/or add an entry. Pass a POINTER to the key as well as a
- // a POINTER to the value to be added. kODErrOutOfMemory is thrown if
- // the entry cannot be added.
-
- ODVMethod void RemoveEntry(ODKeyPtr key);
- // Pass a POINTER to the key.
-
- ODVMethod ODBoolean GetValue(ODKeyPtr key, ODEntryPtr value);
- // Pass a POINTER to the key as well as a POINTER to the value to be
- // retrieved. kODTrue is returned if the key was found, kODFalse
- // otherwise.
-
- ODVMethod ODBoolean Exists(ODKeyPtr key);
- // Check to see if a key exists. This function is no faster than
- // GetValue and should probably only be used when you do not intend to
- // fetch the value immediately. kODTrue is returned if the key exists,
- // kODFalse, otherwise.
-
- protected:
-
- HashTable fSIHashTable;
- ODUShort fValueSize;
-
- HashTable GetSIHashTable();
- };
-
- //==============================================================================
- // SIHashTableIterator
- //
- // This iterator is only meant to be used in the the context of a for loop,
- // e.g.:
- //
- // SIHashTableIterator iter;
- // for (iter.First(key, value); iter.IsNotComplete(); iter.Next(key, value))
- // {
- // ...
- // }
- //
- //==============================================================================
-
- class SIHashTableIterator
- {
- public:
- SIHashTableIterator(SIHashTable* table);
- ~SIHashTableIterator();
-
- void First(ODKeyPtr key, ODEntryPtr value);
- void Next(ODKeyPtr key, ODEntryPtr value);
- ODBoolean IsNotComplete();
- private:
- SIHashTable* fTable;
- ODSLong fIndex;
- ODBoolean fDone;
- ODBoolean GetNext(ODKeyPtr key, ODEntryPtr value);
- };
-
- #endif // _SIHSHTBL_